function [res,cofs]=ldtrend(x); 
%function [res,cofs]=ldtrend(x); 
% Linear Detrending 
n=length(x); 
c=ones(n,1); 
t=1:1:n; 
[cofs,junk,res]=regress(x,[c t'] ); 
